var Base = require('geoClockBase');

// 时针转一圈的秒数
const HOUR_CIRCLE_SECONDS = 43200.0;// 60 * 60 * 12
// 分针转一圈的秒数
const MINUTE_CIRCLE_SECONDS = 3600.0;// 60 * 60
// 秒针转一圈的秒数
const SECOND_CIRCLE_SECONDS = 60.0;

cc.Class({
    extends: Base,

    properties: {
        hourPoiner: {
            default: null,
            type: cc.Node,
            tooltip: '时针'
        },
        minutePointer: {
            default: null,
            type: cc.Node,
            tooltip: '分针'
        },
        secondPointer: {
            default: null,
            type: cc.Node,
            tooltip: '秒针'
        },
    },
    /**
     * 重载
     */
    updateClock(hours, minutes, seconds, milliseconds) {
        // 换算为12小时制
        hours = hours % 12;
        // 换算成总秒数
        var v =
            hours * MINUTE_CIRCLE_SECONDS
            + minutes * SECOND_CIRCLE_SECONDS
            + seconds;
        // 换算成角度
        var angleHour = 360 * (v / HOUR_CIRCLE_SECONDS);
        var angleMinute = 360 * (v / MINUTE_CIRCLE_SECONDS);
        var angleSecond = 360 * (v / SECOND_CIRCLE_SECONDS);
        // 设置表针
        this.hourPoiner && (this.hourPoiner.rotation = angleHour);
        this.minutePointer && (this.minutePointer.rotation = angleMinute);
        this.secondPointer && (this.secondPointer.rotation = angleSecond);
    },
});
